<template><!--测验报告-->
  <div class="warp-2" style="height:100%;">
          <navbar :title="$t('errorBank')" :backCallback="backList"></navbar>
          <div style="width: 100%;overflow-x: hidden;height: 100%;margin-top: 56px;">
                <div>
                  <van-search v-model="pageParmas.keyword"
                    :placeholder="$t('please_input_subject_keyword')"
                    @search="changeSearch"></van-search>
                </div>
                <div style="margin: 0 10px;">
                  <van-dropdown-menu active-color="#075ebb">
                    <van-dropdown-item @change="changeSearch" v-model="pageParmas.examId" :options="examOptionList" />
                    <van-dropdown-item @change="changeSearch" v-model="pageParmas.correct" :options="statusList" />
                    <van-dropdown-item @change="changeSearch" v-model="pageParmas.queType" :options="queTypeList" />
                  </van-dropdown-menu>
                </div>
                <!-- 列表 -->
                <div class="scroll-box">
                    <van-pull-refresh v-model="isRefresh" @refresh="onPulldownTop" loading-text="loading" pulling-text="" loosing-text="" style="height: 100%;">
                        <van-list ref="scroll"
                        v-model="isLoading"
                        :finished="finished"
                        :finished-text="(finished&&totalRecord>0) ? $t('no_more') : ''"
                        loding-text="loading"
                        @load="getExamDetail"
                        >
                        <!-- <course-list-item :list="examList" :isExam="true" v-if="examList.length>0"></course-list-item> -->
                            <template v-if="question.length>0">
                            <div class="white-bg" style="margin: 20px 10px;padding: 10px 0;" v-for="(que, index) in question" :key="index" :ref="index">
                                <div class="word-title-10">
                                    <p class="paddingLR15 font-size16">
                                        {{ (index + 1) > 9 ? (index + 1) : ('0' + (index + 1)) }}.
                                        <span v-html="imgHandle(que.questionInfoDTO.content)"></span>
                                        [{{ showQuesType(que) }}]
                                    </p>
                                </div>
                                <!--单选题-->
                                <mcSingleQues :que="que" style="padding-top: 5px;" v-if="que.questionInfoDTO.type && que.questionInfoDTO.type === 'MC'"></mcSingleQues>
                                <!--多选题-->
                                <mcManyques :que="que" style="padding-top: 5px;" v-if="que.questionInfoDTO.type && que.questionInfoDTO.type == 'MCQ'"></mcManyques>
                                <!--判断题-->
                                <tfQues :que="que" style="padding-top: 5px;" v-if="que.questionInfoDTO.type && que.questionInfoDTO.type === 'TF'"></tfQues>
                                <!--配对题-->
                                <mtQues :que="que" style="padding-top: 5px;" v-if="que.questionInfoDTO.type && que.questionInfoDTO.type == 'MT'"></mtQues>
                                <!--填空题-->
                                <fbQues :que="que" style="padding-top: 5px;" v-if="que.questionInfoDTO.type && que.questionInfoDTO.type == 'FB'"></fbQues>
                            </div>
                            </template>
                            <!--暂无数据-->
                            <div v-if="!isLoading && totalRecord === 0" style="height:100%;">
                                <div class="box-table" style="width:100%;height:100%;">
                                    <div class="box-table-cell" style="text-align: center;">
                                        <div class="no-data">
                                            <img src="../../../static/images/no-data.png" alt=""/>
                                            <p class="color999">{{ $t('no_data') }}</p>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <common-loading :isLoading="isLoading"></common-loading>
                        </van-list>
                    </van-pull-refresh>
                </div>
          </div>
          <div class="loading" v-if="isLoading">
              <div >
                  <div style="width: 33px;height: 33px;">
                      <img src="../../../static/images/loading.gif" alt="" style="width: 100%"/>
                  </div>
                  <div>{{ $t("lab_loading") }}</div><!--加载中...-->
              </div>
          </div>
  </div>
</template>

<script>
import mcSingleQues from './error-detail-components/mc-single-ques.vue';
import tfQues from './error-detail-components/tf-ques.vue';
import mcManyques from './error-detail-components/mc-many-ques.vue';
import mtQues from './error-detail-components/mt-ques.vue';
import fbQues from './error-detail-components/fb-ques.vue';
import {Search, Icon, DropdownMenu, DropdownItem} from 'vant';
import CommonLoading from '@/components/common/loading';
export default {
    name: 'TestingReport',
    components: {
        mcSingleQues,
        tfQues,
        mcManyques,
        mtQues,
        fbQues,
        [Search.name]: Search,
        Icon,
        DropdownMenu,
        DropdownItem,
        CommonLoading
    },
    data() {
        return {
            question: [], // 题目和选项
            pageParmas: {
                examId: '',
                correct: '',
                queType: '',
                keyword: '',
                size: 5,
                current: 1
            },
            totalRecord: 0,
            examOptionList: [],
            incorrectCnt: 0, //答错题目数
            correctCnt: 0, //答对题目数
            isLoading: false,
            moreQue: false, //当考试目录大于12条的时候隐藏12条以上的题目目录
            moreBtn: true, //考试目录更多按钮
            practiceInfo: {},
            statusList: [],
            queTypeList: [],
            maxPageNo: 0,
            finished: false,
            isRefresh: false
        };
    },
    mounted() {
        if (this.$route.query.type === '0' || this.$route.query.type === 0 || this.$route.query.type) {
            this.pageParmas.correct = Number(this.$route.query.type);
        }
        this.getExamOption();
        this.getExamDetail('refresh');
        this.statusList = [
            { text: this.$t('all_type'), value: '' },
            { text: this.$t('not_mastered'), value: 0 },
            { text: this.$t('mastered'), value: 1 }
        ];
        this.queTypeList = [
            { text: this.$t('all_que_type'), value: '' },
            { text: this.$t('Mc_sin'), value: 'MC' },
            { text: this.$t('MCQ'), value: 'MCQ' },
            { text: this.$t('TF'), value: 'TF' },
            { text: this.$t('FB'), value: 'FB' },
            { text: this.$t('MT'), value: 'MT' }
        ];
    },
    methods: {
        /**
         * 下拉刷新
         * */
        onPulldownTop() {
            this.isRefresh = true;
            setTimeout(() => {
                this.finished = false;
                this.pageParmas.current = 1;
                this.getExamDetail('refresh');
                this.isRefresh = false;
            }, 900);
        },
        getExamOption() {
            this.$axios({
                method: 'GET',
                url: `/app/api/trainee/error-question/user/${localStorage.getItem('loginUser')}/exam`
            }).then(res => {
                this.examOptionList = [{ text: this.$t('all_sources'), value: '' }];
                res.data.forEach(item => {
                    this.examOptionList.push({
                        text: item.examName,
                        value: item.examId
                    });
                });
            });
        },
        changeSearch() {
            this.$refs.scroll.scrollTop = 0;
            this.pageParmas.current = 1;
            this.getExamDetail('refresh');
        },
        //获取练习答题详情
        getExamDetail(option) {
            this.isLoading = true;
            this.$axios({
                method: 'GET',
                url: `/app/api/trainee/error-question/user/${localStorage.getItem('loginUser')}/page`,
                params: this.pageParmas
            }).then(res => {
                if (res.data.results) {
                    if (option && option === 'refresh') {
                        this.question = res.data.results;
                    } else {
                        this.question = this.question.concat(res.data.results);
                    }
                }
                this.maxPageNo = res.data.totalPage;
                this.pageParmas.current = res.data.pageNo;
                this.totalRecord = res.data.totalRecord;
                this.isLoading = false;
                this.pageNo++;
                if (this.question.length >= this.totalRecord) {
                    this.finished = true;
                }
            });
        },
        backList() {
            this.$router.push(`/myBank/${localStorage.getItem('loginUser')}`);
        },
        formatTime(timeTotal) {
            let h = parseInt(timeTotal / 60 / 60 % 24);
            h = h < 10 ? '0' + h : h;
            let m = parseInt(timeTotal / 60 % 60);
            m = m < 10 ? '0' + m : m;
            let s = parseInt(timeTotal % 60);
            s = s < 10 ? '0' + s : s;
            const time = h + ':' + m + ':' + s;
            return time;
        },
        /*考试目录id*/
        navId(index) {
            return 'navid_' + index;
        },
        moreDirectory() { //考试目录更多的按钮
            this.moreQue = true;
            this.moreBtn = false;
        },
        imgHandle(txt) {
            let parser = new DOMParser();
            let dom = parser.parseFromString(txt, 'text/html');
            // 处理auido标签
            let audioTags = dom.querySelectorAll('audio');
            audioTags.forEach(audioTag => {
                let src = audioTag.getAttribute('src');
                if (src) {
                    audioTag.setAttribute('src', this.appUrl + src);
                }
            });
            // 处理 <video> 标签
            let videoTags = dom.querySelectorAll('video');
            videoTags.forEach(videoTag => {
                let src = videoTag.getAttribute('src');
                if (src) {
                    videoTag.setAttribute('src', this.appUrl + src);
                }
            });
            // 处理 <img> 标签
            let imgTags = dom.querySelectorAll('img');
            imgTags.forEach(imgTag => {
                let src = imgTag.getAttribute('src');
                if (src) {
                    imgTag.setAttribute('src', this.appUrl + src);
                }
            });
            let htmlContent = dom.documentElement.innerHTML;
            htmlContent = htmlContent.replace(/<head>[.\s\S]*?<\/head>/, '').replace(/<body>|<\/body>/g, '');

            return htmlContent;
        },
        /**
         * 展示题型
         * */
        showQuesType(item) {
            if (item.questionInfoDTO.type === 'MC') {
                return this.$t('Mc_sin');
            } else if (item.questionInfoDTO.type === 'MCQ') {
                return this.$t('Mc');
            } else if (item.questionInfoDTO.type === 'FB') {
                return this.$t('FB');
            } else if (item.questionInfoDTO.type === 'TF') {
                return this.$t('TF');
            } else if (item.questionInfoDTO.type === 'MT') {
                return this.$t('MT');
            }
        }
    },
    watch: {
    },
    //英文序号
    filters: {
        enNo(value) {
            return String.fromCharCode(65 + value);
        }
    }
};
</script>

<style scoped lang="less">
  .box-20 {
      height: 44px;
      line-height: 44px;
  }
  .box-21 {
      width: 100%;
      background: #26282e;
      overflow: hidden;
      p {
          height: 41px;
          line-height: 41px;
      }
  }
  .num-list-01 {
      div {
          display: inline-block;;
          width: 58px;
          height: 58px;
          color: #959ba6;
          text-align: center;
          font-size: 16px;
          font-weight: bold;
          position: relative;
          &.cur {
              color: #ffffff;
          }
          b {
              display: block;
              line-height: 58px;
          }
          .num-cur {
              width: 5px;
              height: 5px;
              display: inline-block;
              border-radius: 50%;
              background: rgba(255,255,255,0.3);
              padding: 2px;
              position: absolute;
              bottom: 6px;
              left: 24px;
              em {
                  width: 5px;
                  height: 5px;
                  display: block;
                  border-radius: 50%;
                  background: #ffffff;
              }
          }
      }
  }
  .first-place-icon {
      background-position: 7px -24px;
      position: absolute;
      top: 0;
      left: 15px;
  }
  .box-22 {
      width: 100%;
      height: 100px;
      background: #075ebb;
      color: #ffffff;
      position: relative;
      & > div {
          width: calc(100% - 116px);
          float: left;
          p:nth-of-type(1) {
              font-size: 30px;
          }
      }
      i {
          float: left;
          height: 20px;
          border-left: 1px solid #3f71d5;
          margin-top: 40px;
      }
      & > p {
          width: 115px;
          float: left;
          line-height: 100px;
          text-align: center;
      }
  }
  .triangle-icon {
      width: 20px;
      height: 10px;
      background: url(./images/triangle-icon.png) no-repeat;
      background-size: 100%;
      position: absolute;
      bottom: -1px;
      left: 20px;
  }
  .module-list-16 {
      width: 100%;
      border: 1px solid #e6e6e6;
      border-radius: 4px;
      li {
          width: calc(100% / 2);
          float: left;
          padding: 20px 15px;
          box-sizing: border-box;
          .circle {
              width: 8px;
              height: 8px;
              border: 1px solid #00af78;
              background: #a1e5d0;
              border-radius: 50%;
              display: inline-block;
              margin-right: 5px;
          }
          .proportion {
              width: 100px;
              height: 8px;
              background: #f5f5f5;
              border-radius: 4px;
              margin-top: 8px;
              float: left;
              i {
                  float: left;
                  display: inline-block;
                  height: 8px;
                  border-radius: 4px;
              }
          }
          &.right {
              .proportion {
                  i {
                      background: #00af78;
                  }
              }
          }
          &.wrong {
              .circle {
                  border-color: #fc355d;
                  background: #fff2f5;
              }
              .proportion {
                  i {
                      background: #fc355d;
                  }
              }
          }
          &.part {
              .circle {
                  border-color: #333333;
                  background: #f5f5f5;
              }
              .proportion {
                  i {
                      background: #333333;
                  }
              }
          }
          &.not-yet {
              .circle {
                  border-color: #075ebb;
                  background: #f2f7ff;
              }
              .proportion {
                  i {
                      background: #075ebb;
                  }
              }
          }
      }
      li:nth-of-type(odd) {
          border-right: 1px solid #e6e6e6;
      }
      li:nth-of-type(1), li:nth-of-type(2) {
          border-bottom: 1px solid #e6e6e6;
      }
  }
  .module-list-17 {
      padding: 0 0 0 15px;
      a {
          float: left;
          width: 44px;
          height: 44px;
          border-radius: 50%;
          text-align: center;
          line-height: 44px;
          margin: 15px 13px 0 0;
          font-size: 18px;
          background: #f2fffb;
          border: 1px solid #a1e6d0;
          color: #00af78;
          &.wrong {
              background: #fff2f5;
              border: 1px solid #ffe0e8;
              color: #fc355d;
          }
          &.part, &.more {
              background: #f5f5f5;
              border: 1px solid #e5e5e5;
              color: #333333;
          }
          &.not-yet {
              background: #f2f7ff;
              border: 1px solid #c2d6ff;
              color: #075ebb;
          }
          &.more {
              font-size: 12px;
          }
      }
  }
  .word-title-10 {
      background: #fafafa;
      padding: 15px 0;
  }
  .list-option {
      li {
          .border-box {
              margin: 15px 0 0 0;
              border: 1px solid #e6e6e6;
              border-radius: 4px;
              .title {
                  width: 100%;
                  span {
                      padding: 13px 10px 13px 0;
                      display: block;
                      color: #999999;
                      font-size: 14px;
                  }
              }
          }
      }
  }
  .option-circle {
      display: inline-block;
      padding: 0 0 0 15px;
      box-sizing: border-box;
      &:before {
          content: "";
          display: inline-block;
          width: 16px;
          height: 16px;
          border: 2px solid #cccccc;
          border-radius: 50%;
          margin-bottom: -4px;
      }
      &.cur:before {
          background: url(./images/course-icon.png) no-repeat -2px -338px;
          background-size: 20px;
      }
      &.current:before {
          border-radius: 3px;
      }
      &.current.cur:before {
          background: url(./images/course-icon.png) no-repeat -2px -368px;
          background-size: 20px;
      }
  }
  .answer-box {
      width: 60px;
      height: 100%;
      border-left: 1px solid #e6e6e6;
      span:before {
          content: "";
          display: block;
          width: 15px;
          height: 15px;
          background: url(./images/course-icon.png) no-repeat 0 -318px;
          background-size: 15px;
          margin: 0 auto;
      }
      span.wrong:before {
          background-position: 0 -298px;
      }
  }
  .box-23 {
      .line {
          float: left;
          width: 100%;
          border-top: 1px solid #e6e6e6;
      }
      .title {
          float: left;
          padding-right: 20px;
          background: #ffffff;
          margin-top: -11px;
      }
  }
  .box-line {
      font-size: 14px;
      color: #1a1a1a;
      border-bottom: 1px solid #1a1a1a;
      padding: 0 10px;
      margin: 0 8px;
  }
  .rightTitle {
      color: #00af78;
  }
  .wrongTitle {
      color: #fc355d;
  }
  .partTitle {
      color: orange;
  }
  .not-yetTitle {
      color: #075ebb;
  }
  .loading{
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      z-index: 999;
      &>div{
          width: 112px;
          height: 112px;
          background: rgba(0,0,0,.5);
          position: absolute;
          top: 0;
          left: 0;
          right: 0;
          bottom: 0;
          margin: auto;
          color: #ffffff;
          display: flex;
          justify-content: center;
          align-items: center;
          flex-direction: column;
          border-radius: 16px;
          &>div:first-child{
              margin-bottom: 5px;
          }
      }
  }
  .re-rating-btn {
      line-height: 20px;
      background: #f7a900;
      color: #fff;
      border-radius: 3px;
      width: 80px;
      background-size: 40px;
      padding: 3px;
  }
  .noData{
    margin: 150px auto;
  }
  .modal-title {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    &.many-modal-title{
      margin-top: 20px;
    }
    p {
      display: flex;
      flex-direction: column;
      align-items: center;
      width: 25%;
    }
    .title-value {
      display: inline-block;
      width: 100%;
      font-size: 18px;
      font-weight: 400;
      color: #333333;
      text-align: center;
      padding: 10px 0 20px;
      border-right: 1px solid #eeeeee;
    }
    .progress {
      color: #00ba5f;
    }
    .catalog-active {
      color: #075ebb;
    }
    .noboder {
      border: none;
    }
  }
  /deep/.van-search{
    background-color:#eff1f4;
  }
  /deep/.van-search__content{
    background-color:#fff;
  }
  .scroll-box{
      height: calc(100% - 110px);
      ul{
          padding: 20px 15px 0;
          li{
              display: flex;
              margin-bottom: 8px;
              /deep/.van-image__img{
                  border-top-left-radius:3px;
                  border-bottom-left-radius:3px;
              }
              .info{
                  flex: 1;
                  padding: 8px 12px;
                  display: flex;
                  flex-direction: column;
                  justify-content: space-between;
                  border-top-right-radius:3px;
                  border-bottom-right-radius:3px;
                  p{
                      margin-bottom: 20px;
                  }
                  .icon{
                      display: flex;
                      justify-content: space-between;
                  }
              }
          }
      }
  }
  .scroll-box{
      /deep/.vue-scroll>div {
          height: 100%;
      }
  }
  /deep/ .van-dropdown-menu__item{
    padding: 0 10px;
  }
  /deep/ .van-dropdown-item{
    margin: 0 10px;
  }
</style>
